var limsProductReportTemplate = Gikam.getPageObject({

    getEditListColumns : function() {
        return [ {
            checkbox : true
        }, {
            index : true
        }, {
            field : 'templateCode',
            title : 'T_LIMS_PRODUCT_REPORT_TEMPLATE.TEMPLATECODE'
        }, {
            field : 'templateName',
            title : 'T_LIMS_PRODUCT_REPORT_TEMPLATE.TEMPLATENAME',
            validators: ['notEmpty'],
        }, {
            field : 'templateType',
            title : 'T_LIMS_PRODUCT_REPORT_TEMPLATE.TEMPLATETYPE',
            validators: ['notEmpty'],
            type : 'select',
            category : 'sys',
            param : {
                codeCategoryId : 'reportTemplateType'
            },
        }, {
            field : 'templateFileName',
            title : 'T_LIMS_PRODUCT_REPORT_TEMPLATE.TEMPLATEFILENAME',
            validators: ['notEmpty'],
            type : 'choose',
            editor : true,
            single : true,
            category : 'report-template-choose',
            onBeforeChoose: function () {
                return {
                    templateType_SEQ : 'report'
                }
            },
            onAfterChoose : function (rows, index) {
                if (Gikam.isNotEmpty(rows)) {
                    this.setData({
                        index: index,
                        templateId: rows[0].id,
                        templateFileName: rows[0].templateFileName
                    });
                }
            },
            onClean: function (field, value, rowIndex) {
                this.setData({
                    index: rowIndex,
                    templateId: "",
                    templateFileName: ""
                })
            },
        }, {
            field : 'remark',
            title : 'T_LIMS_PRODUCT_REPORT_TEMPLATE.REMARK',
            editor : true
        } ];
    },

    getBaseInfoFormFields : function() {
        return [ {
            field : 'templateName',
            title : 'T_LIMS_PRODUCT_REPORT_TEMPLATE.TEMPLATENAME',
            preInsert : true,
        }, {
            field : 'templateType',
            title : 'T_LIMS_PRODUCT_REPORT_TEMPLATE.TEMPLATETYPE',
            type : 'select',
            category : 'sys',
            param : {
                codeCategoryId : 'reportTemplateType'
            },
            firstBlank : false,
            preInsert : true,
            validators : ['notEmpty']
        }, {
            field : 'templateFileName',
            title : 'T_LIMS_PRODUCT_REPORT_TEMPLATE.TEMPLATEFILENAME',
            validators : [ 'strLength[0,33]' ],
            preInsert : true,
            type : 'choose',
            single : true,
            category : 'report-template-choose',
            onBeforeChoose: function () {
                return {
                    templateType_SEQ : 'report'
                }
            },
            onAfterChoose : function (rows, index) {
                if (Gikam.isNotEmpty(rows)) {
                    this.setData({
                        templateId: rows[0].id,
                        templateFileName: rows[0].templateFileName
                    });
                }
            },
        }];
    },

    getChooseListColumns : function() {
        return [{index: true}, {
            field : 'templateCode',
            title : 'T_LIMS_PRODUCT_REPORT_TEMPLATE.TEMPLATECODE'
        }, {
            field : 'templateName',
            title : 'T_LIMS_PRODUCT_REPORT_TEMPLATE.TEMPLATENAME'
        }, {
            field : 'templateType',
            title : 'T_LIMS_PRODUCT_REPORT_TEMPLATE.TEMPLATETYPE'
        }, {
            field : 'templateFileName',
            title : 'T_LIMS_PRODUCT_REPORT_TEMPLATE.TEMPLATEFILENAME'
        }, {
            field : 'remark',
            title : 'T_LIMS_PRODUCT_REPORT_TEMPLATE.REMARK'
        }, ];
    },

    getClientProductListColumns : function() {
        return [ {
            checkbox : true
        }, {
            index : true
        }, {
            field : 'clientCode',
            title : 'T_LIMS_REPORT_CLIENT_PRODUCT.CLIENTCODE'
        }, {
            field : 'clientName',
            title : 'T_LIMS_REPORT_CLIENT_PRODUCT.CLIENTNAME'
        }, {
            field : 'productCode',
            title : 'T_LIMS_REPORT_CLIENT_PRODUCT.PRODUCTCODE'
        }, {
            field : 'ext$.productname',
            title : 'T_LIMS_PRODUCT_MAIN.PRODUCTNAME',
            validators: ['notEmpty'],
        }  ];
    },

    getClientProductFormFields : function() {
        return [ {
            field : 'productNames',
            title : 'T_LIMS_PRODUCT_MAIN.PRODUCTNAME',
            preInsert : true,
            validators : [ 'notEmpty' ],
            type : 'choose',
            single : false,
            category: 'product-choose',
            onBeforeChoose: function () {
                return {
                    status_EQ: '1',
                }
            },
            onAfterChoose: function (rows, index) {
                if (Gikam.isNotEmpty(rows)) {
                    this.setData({
                        productIds: rows.map(e => e.id).join(','),
                        productNames: rows.map(e => e.productName).join(','),
                    })
                }
            },
            onClean: function (field, value, rowIndex) {
                this.setData({
                    productIds: "",
                    productNames: "",
                })
            },
        },  {
            field : 'clientName',
            title : 'T_LIMS_CLIENT.CLIENTNAME',
            preInsert : true,
            type: 'choose',
            category: 'client-choose',
            single: true,
            onBeforeChoose : function(){
                return {
                    clientStatus_EQ: '1'
                }
            },
            onAfterChoose: function (rows, index) {
                if (rows) {
                    this.setData({
                        clientId: rows[0].id,
                        clientCode: rows[0].clientCode,
                        clientName: rows[0].clientName,
                    })
                }
            },
            onClean: function () {
                this.setData({
                    clientId: '',
                    clientCode: '',
                    clientName: '',
                })
            },
        }, ];
    },

    baseUrl : IFM_CONTEXT + '/secure/basemodule/coredata/product-report-templates',
    clientProductUrl : IFM_CONTEXT + '/secure/basemodule/coredata/report-client-products'
});
